﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Easy_917_ReverseOnlyLetters
{
    class MainProject
    {
        static void Main(string[] args)
        {
            Console.WriteLine(ReverseOnlyLetters("Test1ng-Leet=code-Q!"));
            Console.ReadKey();
        }
        public static string ReverseOnlyLetters(string s)
        {
            Stack<char> sta = new Stack<char>();

            foreach (var item in s)
            {//97-122
                if ((97 <= item && item <= 122) || (65 <= item && item <= 90))
                {
                    sta.Push(item);
                }
            }
            char[] arrS = s.ToArray();

            int index = 0;

            while (sta.Count > 0)
            {
                if ((97 <= arrS[index] && arrS[index] <= 122) || (65 <= arrS[index] && arrS[index] <= 90))
                {
                    arrS[index] = sta.Pop();
                }
                index++;
            }
            string str = string.Empty;
            for (int i = 0; i < arrS.Length; i++) str += arrS[i];
            return str;
        }

    }
}
